package com.yl.module.common.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.google.common.eventbus.AsyncEventBus;
import com.yl.module.base.controller.BaseController;
import com.yl.module.common.vo.TextMailForm;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

/**
 * @Todo
 * @Author jiangtao
 * @CreateBy 2020-06-15 5:23 PM
 * @UpdateBy jiangtao
 * @Version v1.0
 */
@Slf4j
@RestController
@RequestMapping("api")
public class ApiTestController extends BaseController {

    @Autowired
    private AsyncEventBus asyncEventBus;

    @PostMapping("send")
    public JSONObject sendTextMail(@RequestBody @Valid TextMailForm form, BindingResult bindingResult) {
        log.error("数据：{}", JSON.toJSONString(form));
        JSONObject obj = new JSONObject();
        obj.put("code", 200);
        obj.put("message", "success");
        asyncEventBus.post(form);
        return obj;
    }
}
